<template>
  <div>
    <top-nav-bar :applyPageRoute="$route.meta.title" @back="$router.go(-1)"></top-nav-bar>
    <a-card :bordered="false">
      <select-student @getStudent="studentInfos" ref="selStudent" />
    </a-card>
    <a-card :bordered="false" style="margin-top: 8px">
      <div v-if="studentInfo">
        <p class="title">转出信息</p>
        <div>
          <div style="display: flex">
            <div style="margin-right: 15px">
              <span>校区信息：</span>
              <span>
                <a-select
                  style="width: 200px"
                  placeholder="请选择校区"
                  v-model="form.structures_id"
                  @change="getReturnCourse"
                  :disabled="form.transfer_out.project_id == undefined ? false : true"
                  allowClear
                >
                  <a-select-option
                    v-for="(item, index) in studentInfo.couserInfo.structures_ids"
                    :key="index"
                    :value="item.id"
                    >{{ item.name }}</a-select-option
                  >
                </a-select>
              </span>
            </div>
            <div v-if="form.structures_id">
              <span>转出课程：</span>
              <a-select
                style="width: 220px"
                placeholder="请选择课程"
                v-model="form.transfer_out.project_id"
                @change="getOrder"
                allowClear
              >
                <a-select-option v-for="(item, index) in courseList" :key="index" :value="item.id">{{
                  item.name
                }}</a-select-option>
              </a-select>
            </div>
          </div>
          <div class="mt16" v-if="!form.transfer_out.project_id">
            <img src="~@/assets/img/returnclass.png" />
            <div class="mt8">请先从左上角选择转出课程</div>
          </div>
          <div class="mt16" v-if="form.transfer_out.project_id && orderArr.length > 0 && isArrears == 1">
            <a-table
              :columns="orderColumns"
              :data-source="orderArr"
              :pagination="false"
              class="user_management_table"
              style="border: 1px solid #e8e8e8"
            >
              <!-- 表格头部插入 -->
              <span slot="customTitle">
                单价
                <a-tooltip>
                  <template slot="title">单价=（总价-优惠金额-优惠券抵扣-赠送金额抵扣）/购买数量</template>
                  <a-icon type="question-circle" theme="filled" style="color: #bfbfbf; margin-left: 5px" />
                </a-tooltip>
              </span>
              <span slot="lossTitle">
                手续费/亏损费
                <a-tooltip>
                  <template slot="title">
                    <div style="margin-bottom: 10px">
                      手续费：指机构根据规定在退转课时收取学员额外的费用。当退转出金额少于应退转出金额时，将产生手续费。
                    </div>
                    <div>
                      亏损费：指机构在退转课时支付退课额外的费用。当退转出金额超过应退转出金额时，将产生亏损费。
                    </div>
                  </template>
                  <a-icon type="question-circle" theme="filled" style="color: #bfbfbf; margin-left: 5px" />
                </a-tooltip>
              </span>
              <span slot="unit_price" slot-scope="text,record">
                  {{record.price_type==1?record.unit_price+'元/课时':record.unit_price+'元/天'}}
              </span>
              <span slot="order_NO" slot-scope="text, record">
                <a @click="openOrderModel(record)">{{ record.order.order_no }}</a>
              </span>
              <span slot="surplus_buy_number" slot-scope="text,record">
                {{record.surplus_buy_number}}
                <span v-if="record.price_type==1">课时</span>
                <span v-if="record.price_type==2">天</span>
              </span>
              <span slot="surplus_give_number" slot-scope="text,record">
                {{record.surplus_give_number}}
                <span v-if="record.price_type==1">课时</span>
                <span v-if="record.price_type==2">天</span>
              </span>
              <span slot="returnBuyNumber" slot-scope="text, record, index">
                <a-input-number
                  style="margin-right: 5px"
                  :min="0"
                  :max="record.surplus_buy_number"
                  v-model="record.returnBuyNumber"
                  @change="changeReturnBuyNumber($event, record, index)"
                />
                {{ record.price_type == 1 ? '课时' : '天' }}
              </span>

              <span slot="returnGiveNumber" slot-scope="text, record, index">
                <a-input-number
                  style="margin-right: 5px"
                  :min="0"
                  :max="record.surplus_give_number"
                  v-model="record.returnGiveNumber"
                  @change="changeReturnGiveNumber($event, record, index)"
                />
                {{ record.price_type == 1 ? '课时' : '天' }}
              </span>
              <span slot="surplusMoney" slot-scope="text, record">￥{{
                record.unit_price * record.surplus_buy_number
              }}</span>

              <span slot="returnMoney" slot-scope="text, record, index">
                ￥
                <a-input-number
                  :min="0"
                  v-model="record.returnMoney"
                  @change="changeReturnMoney($event, record, index)"
                />
              </span>

              <span slot="lossMoney" slot-scope="text, record">
                <div v-if="record.serviceSumMoney">
                  <div v-if="record.serviceSumMoney - record.serviceMoney == 0">￥0.00</div>
                  <div v-if="record.serviceSumMoney - record.serviceMoney > 0">
                    <div style="color: rgb(42, 194, 80)">￥{{ record.serviceSumMoney - record.serviceMoney }}</div>
                    <div>（手续费）</div>
                  </div>
                  <div v-if="record.serviceSumMoney - record.serviceMoney < 0">
                    <div style="color: rgb(255, 79, 79)">
                      ￥{{ Math.abs(record.serviceSumMoney - record.serviceMoney) }}
                    </div>
                    <div>（亏损费）</div>
                  </div>
                </div>
                <div v-else>
                  <div v-if="record.surplus_buy_number * record.unit_price - record.returnMoney == 0">￥0.00</div>
                  <div v-if="record.surplus_buy_number * record.unit_price - record.returnMoney > 0">
                    <div style="color: rgb(42, 194, 80)">
                      ￥{{ record.surplus_buy_number * record.unit_price - record.returnMoney }}
                    </div>
                    <div>（手续费）</div>
                  </div>
                  <div v-if="record.surplus_buy_number * record.unit_price - record.returnMoney < 0">
                    <div style="color: rgb(255, 79, 79)">
                      ￥{{ Math.abs(record.surplus_buy_number * record.unit_price - record.returnMoney) }}
                    </div>
                    <div>（亏损费）</div>
                  </div>
                </div>
              </span>
              <span slot="action" slot-scope="text, record, index">
                <a-checkbox @change="remove($event, record, index)" :defaultChecked="true" />
              </span>
            </a-table>
            <div style="text-align: right; margin-top: 8px">
              转出合计：
              <span class="sum-money">￥{{ returnSumMoney }}</span>
            </div>
          </div>
          <div style="margin-bottom: 16px" v-if="form.transfer_out.project_id && orderArr.length > 0 && isArrears == 2">
            <a-alert
              message="此课程存在欠费，为了能准确对该课程进行对账和计算课消金额，请先补交欠费订单后再转课。"
              banner
              style="margin: 10px 0"
            />
            <div v-for="(item, index) in orderArr" :key="index" class="mb10">
              欠费订单：{{ item.order_no }}（欠费¥{{ item.price }}）
              <a @click="afterPayMent(item)">去补交></a>
            </div>
          </div>
        </div>
        <p class="title" v-if="isArrears == 1">转入信息</p>
        <div v-if="isArrears == 1">
          <div>
            <a-button type="primary" class="mr8" @click="showChild('courseComponents')">选择课程</a-button>
            <a-button type="primary" class="mr8" @click="showChild('itemComponents')">选择物品</a-button>
            <a-button type="primary" class="mr8" @click="showChild('cost')">选择费用</a-button>
          </div>
          <div v-if="data != ''" class="mt16">
            <a-table
              :columns="transferInColumns"
              :data-source="data"
              :pagination="false"
              class="user_management_table"
              style="border: 1px solid #e8e8e8"
            >
              <!-- 购买项目 -->
              <div slot="name" slot-scope="text, record, index">
                <span
                  style="
                    display: inline-block;
                    width: 150px;
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    line-height: 12px;
                  "
                  >{{ record.name }}</span
                >

                <a-select
                  size="small"
                  v-model="record.course_type"
                  class="courseTypeSelectApply"
                  v-if="record.project_type == 1"
                  style="width: 60px; font-size: 10px"
                  @change="changeCourseType(record, index)"
                >
                  <a-select-option :value="0">购买</a-select-option>
                  <a-select-option :value="1">新报</a-select-option>
                  <a-select-option :value="2">续报</a-select-option>
                  <a-select-option :value="3">扩科</a-select-option>
                </a-select>
                <p style="margin-top: 10px" v-if="record.project_type == 1 && record.course_type_num == 2">
                  选择班级：
                  <a-select
                    v-model="record.class_id"
                    style="width: 140px"
                    placeholder="请选择班级"
                    @change="changeCourseType(record, index)"
                    allowClear
                  >
                    <a-select-option v-for="(item, index) in record.class" :key="index" :value="item.id">{{
                      item.name
                    }}</a-select-option>
                  </a-select>
                </p>
              </div>
              <!-- 定价标准 -->
              <span slot="price_rule" slot-scope="text, record, index">
                <span v-if="record.project_type == 1">
                  <a-select
                    v-model="record.price_type"
                    style="width: 200px"
                    v-if="record.price.length > 0"
                    @change="changePriceType(record, index, record.buy_number)"
                  >
                    <a-select-opt-group label="按课时收费">
                      <a-select-option
                        v-for="(item, index) in record.price"
                        :key="index"
                        :value="item.id"
                        v-if="item.type == 1"
                        >{{ item.name }}</a-select-option
                      >
                    </a-select-opt-group>
                    <a-select-opt-group label="按天收费">
                      <a-select-option
                        v-for="(item, index) in record.price"
                        :key="index"
                        :value="item.id"
                        v-if="item.type == 2"
                        >{{ item.name }}</a-select-option
                      >
                    </a-select-opt-group>
                  </a-select>
                </span>
                <span v-else-if="record.project_type == 2">￥{{ record.unit_price }}/笔</span>
                <span v-else-if="record.project_type == 3">￥{{ record.unit_price }}/件</span>
              </span>
              <!-- 购买数量 -->
              <span slot="buyNumber" slot-scope="text, record, index">
                <a-input-number
                  :min="1"
                  v-model="record.buy_number"
                  @change="changeTotalNum(record, index)"
                  :disabled="record.disable"
                />
              </span>
              <!-- 赠送数量 -->
              <span slot="give_num" slot-scope="text, record, index">
                <span v-if="record.project_type == 1">
                  <a-input-number :min="0" v-model="record.give_number" @change="changeTotalNum(record, index)" />
                </span>
                <span v-else>-</span>
              </span>
              <!-- 优惠折扣 -->
              <span slot="disCount" slot-scope="text, record, index">
                <a-input
                  :style="{ width: 'calc(100%)' }"
                  v-model="record.discount.value"
                  @change="changeDiscount(record, index)"
                  onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"
                >
                  <a-select
                    slot="addonBefore"
                    v-model="record.discount.type"
                    style="width: 80px"
                    :defaultValue="1"
                    @change="changeDiscount(record, index)"
                  >
                    <a-select-option :value="1">直减</a-select-option>
                    <a-select-option :value="2">折扣</a-select-option>
                  </a-select>
                </a-input>
              </span>
              <!-- 签约数量 -->
              <span slot="total_number" slot-scope="text, record, index">
                <span v-if="record.project_type == 1">
                  <span v-if="record.choice_combo.type == 2">
                    <span style="display: inline-block; width: 300px; text-align: left; padding-left: 16px">
                      开始日期：
                      <a-date-picker
                        :allowClear="false"
                        v-model="record.buy_start_time"
                        placeholder="不选择默认为当日"
                        @change="changeDate(record, index)"
                      />
                    </span>
                    <br />
                    <span
                      style="
                        display: inline-block;
                        width: 300px;
                        text-align: left;
                        padding-left: 16px;
                        margin-top: 10px;
                      "
                      >结束日期：&nbsp;&nbsp;&nbsp;{{ record.buy_end_time || '--' }} (共{{
                        record.buy_number + record.give_number
                      }}天)</span
                    >
                  </span>
                  <span v-else>
                    <span>{{ record.total_number || '0' }}课时</span>
                  </span>
                </span>
                <span v-else>{{ record.total_number || '0' }}件</span>
              </span>
              <!-- 操作 -->
              <span slot="action" slot-scope="text, record, index">
                <a @click="delProject(record, index)">删除</a>
              </span>
            </a-table>
            <div class="mt8 receivable" v-if="transferInMoney">
              转入合计：
              <span class="receivable_num">￥{{ transferInMoney }}</span>
            </div>
            <div class="pt8 receivable" v-if="returnSumMoney - transferInMoney >= 0">
              应退金额：
              <span class="receivable_num" style="font-size: 24px">￥{{ total }}</span>
            </div>
            <div class="pt8 receivable" v-else>
              应收金额：
              <span class="receivable_num" style="font-size: 24px">￥{{ Math.abs(total) }}</span>
            </div>
          </div>
          <div class="mt16" v-if="data == ''">
            <img src="~@/assets/img/returnclass.png" />
            <div class="mt8">请先从左上角选择转出课程</div>
          </div>
        </div>
      </div>
      <div style="text-align: center" v-else>
        <img src="~@/assets/img/search.png" />
        <div>请点击从左上角按钮搜索学员</div>
      </div>
    </a-card>
    <a-card :bordered="false" style="margin-top: 8px" v-if="data != ''">
      <div class="headertitle">支付信息</div>
      <div class="pay-way" v-if="total >= 0">
        <p class="title">应退金额：￥{{ total }}</p>
        <div class="refund-list">
          <span>退款方式：</span>
          <div
            class="refund-item"
            :class="{ active: courrent == index ? true : false }"
            v-for="(item, index) in btnStyle"
            :key="index"
            @click="handerPayWay(item, index)"
          >
            <a-icon
              :type="item.icon"
              :style="{ color: item.color, 'margin-right': '10px', 'font-size': '15px' }"
            ></a-icon>
            <span>{{ item.text }}</span>
          </div>
        </div>
      </div>
      <div v-else>
        <p class="mytitle">应收金额：￥{{ Math.abs(total) }}</p>
        <div class="mytitle">其他支付方式</div>
        <div class="payWays">
          <div v-for="(item, index) in btnStyle" :key="index" class="payWayBtn">
            <a-checkbox @change="changePayWay($event, item.type, index)" style="width: 128px">
              <a-icon :type="item.icon" :style="{ color: item.color, 'margin-right': '10px' }"></a-icon>
              {{ item.text }}
            </a-checkbox>

            <span v-if="item.check" style="text-align: right">
              <a-input
                style="outline: none; border: none; width: 80px; box-shadow: none; text-align: right"
                onkeyup="this.value=this.value.replace(/[^\d.]/g,'');"
                v-model="item.price"
              ></a-input
              >元
            </span>
          </div>
        </div>
      </div>
    </a-card>
    <a-card :bordered="false" style="margin-top: 8px; margin-bottom: 65px">
      <transfer-info ref="otherInfo" />
    </a-card>
    <div class="footer">
      <!-- <a-button style="margin-right:8px;">取消</a-button> -->
      <a-button type="primary" @click="finishCourse">确认转课</a-button>
    </div>
    <!-- 确认报名弹窗 -->
    <a-modal
      title="确定转课"
      :visible="transferVisible"
      :confirm-loading="transferConfirmLoading"
      @ok="transferHandleOk"
      @cancel="transferHandleCancel"
      :width="1080"
      :bodyStyle="tsstyle"
    >
      <a-alert message="请仔细核对信息，避免信息填写错误。确定转课后，学员即可安排上课。" banner class="mb10" />
      <div class="check-header" v-if="studentInfo" style>
        <span style="color: rgb(51, 51, 51); font-size: 16px">{{ studentInfo.name }}</span>
        <a-icon type="woman" v-if="studentInfo.sex == 0" style="color: rgb(32, 161, 255); margin: 0px 8px" />
        <a-icon type="man" v-if="studentInfo.sex == 1" style="color: rgb(32, 161, 255); margin: 0px 8px" />
        <span v-if="studentInfo.main_parent_type && studentInfo.main_parent_type > 0" style="color: rgb(102, 102, 102)"
          >({{
            studentInfo.main_parent_type == 1
              ? '本人'
              : studentInfo.main_parent_type == 2
              ? '妈妈'
              : studentInfo.main_parent_type == 3
              ? '爸爸'
              : studentInfo.main_parent_type == 4
              ? '爷爷'
              : studentInfo.main_parent_type == 5
              ? '奶奶'
              : studentInfo.main_parent_type == 6
              ? '外公'
              : studentInfo.main_parent_type == 7
              ? '外婆'
              : ''
          }})</span
        >
      </div>
      <div style="color: rgb(51, 51, 51); margin-bottom: 10px">转出信息</div>
      <div style="margin-bottom: 16px" v-if="transferVisible">
        <a-table
          :columns="TransferOutcolumns"
          :data-source="orderArrModel"
          :pagination="false"
          class="user_management_table"
          style="border: 1px solid #e8e8e8"
          ref="table1"
        >
          <span slot="lossMoney" slot-scope="text, record">
            <div v-if="record.serviceSumMoney">
              <div v-if="record.serviceSumMoney - record.serviceMoney == 0">￥0.00</div>
              <div v-if="record.serviceSumMoney - record.serviceMoney > 0">
                <div>￥{{ record.serviceSumMoney - record.serviceMoney }}（手续费）</div>
              </div>
              <div v-if="record.serviceSumMoney - record.serviceMoney < 0">
                <div>￥{{ Math.abs(record.serviceSumMoney - record.serviceMoney) }}（亏损费）</div>
              </div>
            </div>
            <div v-else>
              <div v-if="record.surplus_buy_number * record.unit_price - record.returnMoney == 0">￥0.00</div>
              <div v-if="record.surplus_buy_number * record.unit_price - record.returnMoney > 0">
                <div>￥{{ record.surplus_buy_number * record.unit_price - record.returnMoney }}（手续费）</div>
              </div>
              <div v-if="record.surplus_buy_number * record.unit_price - record.returnMoney < 0">
                <div>
                  ￥{{ Math.abs(record.surplus_buy_number * record.unit_price - record.returnMoney) }}（亏损费）
                </div>
                <div></div>
              </div>
            </div>
          </span>
        </a-table>
        <div style="text-align: right" class="mt8">转出合计：￥{{ returnSumMoney }}</div>
      </div>
      <div style="margin-bottom: 10px">转入信息</div>
      <div>
        <a-table
          :columns="TransferIncolumns"
          :data-source="data"
          :pagination="false"
          class="user_management_table"
          style="border: 1px solid #e8e8e8"
        >
          <span slot="class_id" slot-scope="text, record">
            <span v-if="record.class_id">{{ record.className }}</span>
            <span v-else>-</span>
          </span>
          <!-- 设置日期 -->
          <span slot="setDate" slot-scope="text, record">
            <span v-if="record.project_type == 1">
              <span v-if="record.choice_combo.type == 2">
                <span>{{ moment(record.buy_start_time).format('YYYY-MM-DD') }}~</span>
                <span>{{ record.buy_end_time || '--' }} (共{{ record.buy_number + record.give_number }}天)</span>
              </span>
              <span v-else>
                <span>-</span>
              </span>
            </span>
            <span v-else>-</span>
          </span>
        </a-table>
        <div style="text-align: right" class="mt8">
          <div style="padding: 10px 0">转入合计：￥{{ transferInMoney }}</div>
          <div class="pt8" v-if="returnSumMoney - transferInMoney >= 0">
            应退金额：
            <span style="font-size: 20px; color: #ff8534">￥{{ total }}</span>
          </div>
          <div class="pt8" v-else>
            应收金额：
            <span style="font-size: 20px; color: #ff8534">￥{{ Math.abs(total) }}</span>
          </div>
        </div>
        <div class="mt8">
          <div v-if="returnSumMoney - transferInMoney < 0">
            <div>
              收款方式：
              <span v-if="form.refund_method != ''">
                <span v-for="(item, index) in form.refund_method" :key="index">
                  <span v-if="item.charge_type == 1" style="margin-right: 20px">
                    <a-icon type="alipay-circle" style="color: rgb(24, 144, 255); margin-right: 5px" />支付宝
                  </span>
                  <span v-if="item.charge_type == 2" style="margin-right: 20px">
                    <a-icon type="wechat" style="color: #52c42a; margin-right: 5px" />微信
                  </span>
                  <span v-if="item.charge_type == 3" style="margin-right: 20px">
                    <a-icon type="transaction" style="color: #ff7f24; margin-right: 5px" />现金
                  </span>
                  <span v-if="item.charge_type == 4" style="margin-right: 20px">
                    <a-icon type="global" style="color: #1296db; margin-right: 5px" />网银转账
                  </span>
                  <span v-if="item.charge_type == 5" style="margin-right: 20px">
                    <a-icon type="credit-card" style="color: #39d63e; margin-right: 5px" />POS机刷卡
                  </span>
                </span>
              </span>
              <span v-else>-</span>
            </div>
            <div>
              实收金额：
              <span style="font-size: 20px; color: #ff8534">￥{{ Math.abs(copytotal) }}</span>
            </div>
            <div v-if="Math.abs(total) - Math.abs(copytotal) > 0">
              欠费金额：
              <span style="font-size: 20px; color: #ff8534">￥{{ Math.abs(total) - Math.abs(copytotal) }}</span>
            </div>
          </div>
          <div>
            经办日期：
            <span>{{ form.purchase_at }}</span>
          </div>
        </div>
      </div>
    </a-modal>
    <course-model ref="course" :able="1" @receive="courseData" :isdisable="form.transfer_out.project_id"></course-model>
    <item-model ref="item" :able="1" @receive="itemData"></item-model>
    <cost-model ref="cost" :able="1" @receive="costData"></cost-model>
    <after-pay ref="afterPay" @update="update" />
    <order-model ref="orderModel" />
  </div>
</template>

<script>
import topNavBar from '@/components/topNavBar/topNavBar'
import selectStudent from '@/components/SelectStudent'
import transferInfo from '@/components/transferiInfo'
import courseModel from '@/components/radioCourse'
import itemModel from '@/components/item'
import costModel from '@/components/cost'
import afterPay from '@/components/afterPay'
import orderModel from '@/components/returnOrderModel'
import moment from 'moment'
import { studentCourse, studentCourseList, createTransferCourse } from '@/api/returnInfo'
export default {
  components: {
    orderModel,
    topNavBar,
    selectStudent,
    transferInfo,
    costModel,
    itemModel,
    courseModel,
    afterPay,
  },
  data() {
    return {
      orderArrModel: [],
      transferVisible: false,
      transferConfirmLoading: false,
      TransferOutcolumns: [
        {
          title: '转出课程',
          dataIndex: 'buy_project',
          // scopedSlots: { customRender: 'name' },
        },
        {
          title: '转出购买数量',
          dataIndex: 'returnBuyNumber',
          // scopedSlots: { customRender: 'returnBuyNumber' },
        },
        {
          title: '转出赠送课时',
          dataIndex: 'returnGiveNumber',
          // scopedSlots: { customRender: 'name' },
        },
        {
          title: '转出金额',
          dataIndex: 'returnMoney',

          // scopedSlots: { customRender: 'name' },
        },
        {
          title: '手续费/亏损费',
          dataIndex: 'lossMoney',
          scopedSlots: { customRender: 'lossMoney' },
        },
      ],
      TransferIncolumns: [
        {
          title: '购买的项目',
          dataIndex: 'name',
          // scopedSlots: { customRender: 'name' },
        },
        {
          title: '购买数量',
          dataIndex: 'buy_number',
          // scopedSlots: { customRender: 'name' },
        },
        {
          title: '赠送数量',
          dataIndex: 'give_number',
          // scopedSlots: { customRender: 'name' },
        },
        {
          title: '课程有效期/起止日期',
          scopedSlots: { customRender: 'setDate' },
        },
        {
          title: '班级',
          scopedSlots: { customRender: 'class_id' },
        },
        {
          title: '小计',
          dataIndex: 'signing_price',
          // scopedSlots: { customRender: 'name' },
        },
      ],
      tsstyle: { 'max-height': '70vh', 'overflow-y': 'auto', padding: '24px', 'min-height': '130px' },
      studentInfo: undefined,
      courseSelectRows: [], //被选择的课程在`选择课程`中的回显
      //付款方式
      courrent: 0,
      charge_type: 1,
      btnStyle: [
        {
          type: 1,
          text: '支付宝',
          color: '#1890ff',
          icon: 'alipay-circle',
          check: false,
          price: 0,
        },
        {
          type: 2,
          text: '微信',
          color: '#52c42a',
          icon: 'wechat',
          check: false,
          price: 0,
        },
        {
          type: 3,
          text: '现金',
          color: '#FF7F24',
          icon: 'transaction',
          theme: 'filled',
          check: false,
          price: 0,
        },
        {
          type: 4,
          text: '网银转账',
          color: '#1296db',
          icon: 'global',
          check: false,
          price: 0,
        },
        {
          type: 5,
          text: 'POS机刷卡',
          color: '#39d63e',
          icon: 'credit-card',
          check: false,
          price: 0,
        },
      ],
      form: {
        //
        school_id: this.$store.state.user.school,
        structures_id: undefined,
        student_id: undefined,
        //转出信息
        transfer_out: {
          project_id: undefined,
          project_type: 1,
          order_arr: [],
        },
        //转入信息
        transfer_in: {
          order_arr: [],
        },
        //支付信息
        refund_method: [],
      },
      course_id: undefined,
      courseList: [],
      isArrears: 0, //是否欠费
      //转出订单信息
      orderArr: [],
      orderColumns: [
        {
          title: '订单号',
          scopedSlots: { customRender: 'order_NO' },
        },
        {
          slots: { title: 'customTitle' },
          // title: '单价',
          scopedSlots: { customRender: 'unit_price' },
        },
        {
          title: '剩余购买数量',
          // dataIndex: 'surplus_buy_number',
          scopedSlots: { customRender: 'surplus_buy_number' },
        },
        {
          title: '剩余赠送数量',
          // dataIndex: 'surplus_give_number',
          scopedSlots: { customRender: 'surplus_give_number' },
        },
        {
          title: '剩余金额',
          dataIndex: 'surplusMoney',

          scopedSlots: { customRender: 'surplusMoney' },
        },
        {
          title: '转出购买数量',
          dataIndex: 'returnBuyNumber',
          scopedSlots: { customRender: 'returnBuyNumber' },
        },
        {
          title: '转出赠送数量',
          dataIndex: 'returnGiveNumber',

          scopedSlots: { customRender: 'returnGiveNumber' },
        },
        {
          title: '转出金额',
          dataIndex: 'returnMoney',

          scopedSlots: { customRender: 'returnMoney' },
        },
        {
          slots: { title: 'lossTitle' },

          dataIndex: 'lossMoney',
          scopedSlots: { customRender: 'lossMoney' },
        },
        {
          title: '是否退此订单',
          scopedSlots: { customRender: 'action' },
        },
      ],
      //转入订单信息
      data: [],
      transferInColumns: [
        {
          title: '购买项目',
          width: 300,
          align: 'left',
          // dataIndex: 'unit_price',
          scopedSlots: { customRender: 'name' },
        },
        {
          title: '定价标准',
          // dataIndex: 'unit_price',
          width: 300,
          scopedSlots: { customRender: 'price_rule' },
        },
        {
          title: '购买数量',
          // dataIndex: 'unit_price',
          scopedSlots: { customRender: 'buyNumber' },
        },
        // {
        //   title: '总价',
        //   // dataIndex: 'unit_price',
        //   // scopedSlots: { customRender: 'name' },
        // },
        {
          title: '赠送数量',
          // dataIndex: 'unit_price',
          scopedSlots: { customRender: 'give_num' },
        },
        {
          title: '直减/折扣',
          ellipsis: true,
          width: 200,
          // dataIndex: 'unit_price',
          scopedSlots: { customRender: 'disCount' },
        },
        {
          title: '签约数量/签约时长',
          dataIndex: 'total_number',
          align: 'center',
          width: 310,
          scopedSlots: { customRender: 'total_number' },
        },
        {
          title: '小计',
          dataIndex: 'signing_price',
          // scopedSlots: { customRender: 'name' },
        },
        {
          title: '操作',
          // dataIndex: 'unit_price',
          scopedSlots: { customRender: 'action' },
        },
      ],
      returnSumMoney: 0,
      transferInMoney: 0,
      total: 0,
      copytotal: 0,
    }
  },
  mounted() {
    console.log(this.$route.query)
    if (this.$route.query.studentInfo) {
      // this.studentInfo.couserInfo.structures_ids=[]
      // this.studentInfo.couserInfo.structures_ids.push(this.$route.query.structures)
      this.$nextTick(() => {
        this.studentInfo = this.$route.query.studentInfo
        this.$refs.selStudent.studentInfo = this.studentInfo
        this.form.student_id = this.$route.query.studentInfo.id
        this.form.structures_id = this.$route.query.structures.id
        this.initialization(this.$route.query.course.id)
        if (this.studentInfo.id) {
          studentCourseList(this.studentInfo.id)
            .then((res) => {
              this.$refs.selStudent.studentInfo.couserInfo = res
            })
            .catch((err) => {
              this.$message.error(err.data.message || '课程获取失败')
            })
        }
      })

      console.log(123456)
    }
  },
  methods: {
    moment,
    //查看订单
    openOrderModel(data) {
      this.$refs.orderModel.showModel(data)
    },
    //补交
    afterPayMent(data) {
      this.$refs.afterPay.showModal(data)
    },
    update() {
      if (this.form.structures_id) {
        studentCourse({ student_id: this.form.student_id, structures_id: this.form.structures_id })
          .then((res) => {
            this.courseList = res
            if (this.form.transfer_out.project_id) {
              this.courseSelectRows = []
              this.courseSelectRows.push(this.form.transfer_out.project_id)
              this.courseList.forEach((item) => {
                if (item.type == 1) {
                  if (this.form.transfer_out.project_id == item.id) {
                    this.isArrears = 1
                    this.orderArr = []

                    this.orderArr = item.order
                    if (this.orderArr.length > 0) {
                      this.orderArr.forEach((val) => {
                        val.buy_project = item.name
                        val.project_type = item.project_type
                      })
                    }
                  }
                } else {
                  if (this.form.transfer_out.project_id == item.id) {
                    this.isArrears = 2
                    this.orderArr = []
                    // console.log(item.order, 'hhhhhh')
                    this.orderArr = item.order
                    this.$forceUpdate()
                  }
                }
              })
              this.returnSumMoney = 0
              this.orderArr.forEach((val) => {
                val.unit_price = (val.signing_price / val.buy_number).toFixed(2)
                val.returnBuyNumber = val.surplus_buy_number
                val.returnGiveNumber = val.surplus_give_number
                val.returnMoney = val.unit_price * val.surplus_buy_number
                this.returnSumMoney = this.returnSumMoney + val.returnMoney
                val.out = true
                if (val.out) {
                  this.returnSumMoney = this.returnSumMoney + val.returnMoney
                }
              })
            }
          })
          .catch((err) => {
            this.$success.error(err.data.message || '获取课程失败')
          })
      }
    },
    studentInfos(e) {
      this.studentInfo = e
      this.form.student_id = e.id
      //重新选择清空
      this.form.transfer_out.project_id = undefined
      this.form.structures_id = undefined
      this.data = []
      this.isArrears = 0
    },
    showChild(e) {
      if (e == 'courseComponents') {
        this.$refs.course.showModal(this.courseSelectRows, this.form.structures_id)
      } else if (e == 'itemComponents') {
        this.$refs.item.showModal()
      } else if (e == 'cost') {
        this.$refs.cost.showModal()
      }
    },
    initialization(course_id) {
      if (this.form.structures_id) {
        studentCourse({
          student_id: this.form.student_id,
          structures_id: this.form.structures_id,
          course_id: course_id,
        })
          .then((res) => {
            this.courseList = res
            this.form.transfer_out.project_id = Number(this.$route.query.course.id)
            if (this.form.transfer_out.project_id) {
              this.courseSelectRows = []
              this.courseSelectRows.push(this.form.transfer_out.project_id)
              this.courseList.forEach((item) => {
                if (item.type == 1) {
                  if (this.form.transfer_out.project_id == item.id) {
                    this.isArrears = 1
                    this.orderArr = []

                    this.orderArr = item.order
                    if (this.orderArr.length > 0) {
                      this.orderArr.forEach((val) => {
                        val.buy_project = item.name
                        val.project_type = item.project_type
                      })
                    }
                  }
                } else {
                  if (this.form.transfer_out.project_id == item.id) {
                    this.isArrears = 2
                    this.orderArr = []
                    // console.log(item.order, 'hhhhhh')
                    this.orderArr = item.order
                    this.$forceUpdate()
                  }
                }
              })
              this.returnSumMoney = 0
              this.orderArr.forEach((val) => {
                val.unit_price = (val.signing_price / val.buy_number).toFixed(2)
                val.returnBuyNumber = val.surplus_buy_number
                val.returnGiveNumber = val.surplus_give_number
                val.returnMoney = val.unit_price * val.surplus_buy_number
                val.out = true
                if (val.out) {
                  this.returnSumMoney = this.returnSumMoney + val.returnMoney
                }
              })
            }
          })
          .catch((err) => {
            this.$message.warning(err.message || '获取课程失败')
          })
      }
    },
    getReturnCourse() {
      if (this.form.structures_id) {
        studentCourse({ student_id: this.form.student_id, structures_id: this.form.structures_id })
          .then((res) => {
            this.courseList = res
          })
          .catch((err) => {
            this.$message.error(err.data.message || '获取课程失败')
          })
      }
    },
    getOrder() {
      console.log(this.orderArr, 'cccccc')
      // if (this.orderArr == '') {
      //   this.getReturnCourse()
      // }
      if (this.form.transfer_out.project_id) {
        this.courseSelectRows = []
        this.courseSelectRows.push(this.form.transfer_out.project_id)
        this.courseList.forEach((item) => {
          if (item.type == 1) {
            if (this.form.transfer_out.project_id == item.id) {
              this.isArrears = 1
              this.orderArr = []

              this.orderArr = item.order
              if (this.orderArr.length > 0) {
                this.orderArr.forEach((val) => {
                  val.buy_project = item.name
                  val.project_type = item.project_type
                })
              }
            }
          } else {
            if (this.form.transfer_out.project_id == item.id) {
              this.isArrears = 2
              this.orderArr = []
              // console.log(item.order, 'hhhhhh')
              this.orderArr = item.order
              this.$forceUpdate()
            }
          }
        })
        this.returnSumMoney = 0
        this.orderArr.forEach((val) => {
          val.unit_price = (val.signing_price / val.buy_number).toFixed(2)
          val.returnBuyNumber = val.surplus_buy_number
          val.returnGiveNumber = val.surplus_give_number
          val.returnMoney = val.unit_price * val.surplus_buy_number
          val.out = true
          if (val.out) {
            this.returnSumMoney = this.returnSumMoney + val.returnMoney
          }
        })
      }
    },
    //退还购买课时 改变
    changeReturnBuyNumber(event, data, index) {
      console.log(event)
      console.log('退出购买课时', data)
      data.returnBuyNumber = event
      data.returnMoney = data.returnBuyNumber * data.unit_price
      data.serviceSumMoney = data.returnMoney
      data.serviceMoney = data.serviceSumMoney
      this.orderArr.splice(index, 1, data)
      this.returnSumMoney = 0
      this.orderArr.forEach((item) => {
        if (item.out) {
          this.returnSumMoney = this.returnSumMoney + item.returnMoney
        }
      })
      // console.log(index)
    },
    changeReturnGiveNumber(event, data, index) {
      data.returnGiveNumber = event
      this.orderArr.splice(index, 1, data)
    },
    changeReturnMoney(event, data, index) {
      data.returnMoney = event
      data.serviceMoney = event
      console.log(data, '退出金额改变')
      this.orderArr.splice(index, 1, data)
      this.returnSumMoney = 0
      this.orderArr.forEach((item) => {
        if (item.out) {
          this.returnSumMoney = this.returnSumMoney + item.returnMoney
        }
      })
    },
    remove(e, data, index) {
      if (e.target.checked) {
        data.out = true
      } else {
        data.out = false
      }
      this.orderArr.splice(index, 1, data)
      this.returnSumMoney = 0
      this.orderArrModel = []
      this.orderArr.forEach((item) => {
        if (item.out) {
          this.returnSumMoney = this.returnSumMoney + item.returnMoney
          this.orderArrModel.push(item)
        }
      })
      // this.orderArrModel=JSON.parse(JSON.stringify(this.orderArr))
      // this.orderArrModel.forEach((item)=>{
      //   if(!item.out){
      //     this.orderArrModel.splice(index,1)
      //   }
      // })
    },
    // 选择课程后的参数获取
    courseData(data) {
      let e = JSON.parse(JSON.stringify(data))
      if (e.length > 0) {
        this.status = true
      }
      let choiceCourseArr = []
      e.forEach((val, index) => {
        let arr = []

        this.data.forEach((item) => {
          if (item.project_type == 1) {
            arr.push(item.id)
          }
        })
        choiceCourseArr.push(val.id)
        if (val.price.length > 0) {
          val.project_id = val.id
          val.project_type = 1 //类型：1课程，2物品，3费用
          val.course_type_num = val.type //一对一或一对多  1——>对一 2——>对多
          val.price.forEach((item) => {
            if (item.id) {
              if (item.type == 1) {
                if (item.number == 1) {
                  item.name = item.name + '(' + item.unit_price + '元/课时' + ')'
                } else {
                  item.name = item.name + '(' + item.total_price + '元' + item.number + '课时)'
                }
              } else {
                if (item.id && item.type == 2) {
                  if (item.number == 1) {
                    item.name = item.name + '(' + item.unit_price + '元/天' + ')'
                  } else {
                    item.name = item.name + '(' + item.total_price + '元' + item.number + '天)'
                  }
                }
              }
            }
          })
          val.price_type = val.price[0].id //当前选择的定价标准ID

          val.choice_combo = val.price[0] //当前选择的定价标准 对象
          val.unit_price = val.price[0].unit_price //当前单价
          val.class_id = undefined
          val.total_number = 1
          val.buy_number = val.price[0].number //购买数量
          val.give_number = 0 //赠送数量
          val.signing_price = val.price[0].unit_price //总价
          val.course_type = 3 //表明当前选择课程类型 课程类型：0购买，1新报，2续报，3扩科
          val.buy_start_time = moment()
          let start = new Date(moment(val.buy_start_time).format('YYYY-MM-DD'))
          let end = new Date(moment(val.buy_start_time).format('YYYY-MM-DD'))

          if (val.price[0].type == 2) {
            if (val.price[0].number >= 1) {
              end.setDate(start.getDate() + val.price[0].number)
              let endTime = new Date(end)
              val.buy_end_time =
                endTime.getFullYear() + '-' + (endTime.getMonth() + 1) + '-' + endTime.getDate() || null
            } else {
              end.setDate(start.getDate() + 1)
              val.buy_end_time =
                endTime.getFullYear() + '-' + (endTime.getMonth() + 1) + '-' + endTime.getDate() || null
            }
          }
          val.discount = {
            //优惠方式  type：1直减 2折扣
            type: 1,
            value: 0,
          }
          if (arr.indexOf(val.id) == -1) {
            this.data.push(val)
            this.changePriceType(val, index, 'add')
          }
        } else {
          val.project_id = val.id
          val.project_type = 1 //类型：1课程，2物品，3费用
          val.course_type_num = val.type //一对一或一对多  1——>一对一 2——>一对多
          val.price_type = null //当前选择的定价标准ID
          val.unit_price = null //当前单价
          val.class_id = undefined
          val.total_number = 1
          val.buy_number = 1 //购买数量
          val.give_number = 0 //赠送数量
          val.signing_price = 0 //总价
          val.course_type = 3 //表明当前选择课程类型 课程类型：0购买，1新报，2续报，3扩科
          val.buy_start_time = moment()
          let start = new Date(moment(val.buy_start_time).format('YYYY-MM-DD'))
          let end = new Date(moment(val.buy_start_time).format('YYYY-MM-DD'))
          end.setDate(start.getDate() + val.total_number)
          if (val.total_number > 0 && val.buy_start_time) {
            let endTime = new Date(end)
            val.buy_end_time = endTime.getFullYear() + '-' + (endTime.getMonth() + 1) + '-' + endTime.getDate() || null
          }
          val.discount = {
            //优惠方式  type：1直减 2折扣
            type: 1,
            value: 0,
          }
          if (arr.indexOf(val.id) == -1) {
            this.data.push(val)
          }
        }
      })
      e.forEach((item) => {
        this.itemData(item.goods)
        this.costData(item.costs)
      })
      this.courseSelectRows = choiceCourseArr
    },
    // 选择物品后的参数获取
    itemData(data) {
      data.forEach((val) => {
        val.project_id = val.id
        val.project_type = 2
        val.total_number = 1
        val.buy_number = 1 //购买数量
        val.give_number = 0 //赠送数量
        val.signing_price = val.unit_price //总价
        val.buy_start_time = null
        val.buy_end_time = null
        val.course_type = null
        val.discount = {
          //优惠方式  type：1直减 2折扣
          type: 1,
          value: 0,
        }
        let arr = []
        this.data.forEach((item) => {
          if (item.project_type && item.project_type == 2) {
            arr.push(item.id)
          }
        })
        if (arr.length > 0) {
          if (arr.indexOf(val.id) == -1) {
            this.data.push(val)
          }
        } else {
          this.data.push(val)
        }
      })
    },
    // 选择费用后的参数获取
    costData(params) {
      params.forEach((val) => {
        val.project_id = val.id
        val.project_type = 3
        val.total_number = 1
        val.buy_number = 1 //购买数量
        val.give_number = 0 //赠送数量
        val.signing_price = val.unit_price //总价
        val.buy_start_time = null
        val.buy_end_time = null
        val.course_type = null
        val.discount = {
          //优惠方式  type：1直减 2折扣
          type: 1,
          value: 0,
        }
        let arr = []
        this.data.forEach((item) => {
          if (item.project_type && item.project_type == 3) {
            arr.push(item.id)
          }
        })
        if (arr.length > 0) {
          if (arr.indexOf(val.id) == -1) {
            this.data.push(val)
          }
        } else {
          this.data.push(val)
        }
      })
    },
    //修改购买数量
    changeTotalNum(e, index) {
      if (!e.buy_number || e.buy_number < 1) {
        e.buy_number = 1
      }
      e.total_number = e.buy_number + e.give_number
      let benefit = e.discount.value
      if (e.buy_number > 0) {
        if (e.discount.type == 1 && benefit >= 0) {
          //直减  计算总价
          if (benefit < e.buy_number * e.unit_price) {
            e.signing_price = (e.buy_number * e.unit_price - e.discount.value).toFixed(2)
          } else {
            e.signing_price = 0
          }
        } else if (e.discount.type == 2 && benefit > 0) {
          e.signing_price = (e.unit_price * e.buy_number * e.discount.value).toFixed(2)
        } else if (e.discount.type == 2 && benefit == 0) {
          e.signing_price = (e.unit_price * e.buy_number).toFixed(2)
        }
      } else {
        e.signing_price = 0
      }
      this.changeDate(e, index)
      this.data.splice(index, 1, e)
    },
    //切换开始时间
    changeDate(e, index) {
      let start = new Date(moment(e.buy_start_time).format('YYYY-MM-DD'))
      let end = new Date(moment(e.buy_start_time).format('YYYY-MM-DD'))
      if (e.total_number >= 1) {
        end.setDate(start.getDate() + e.total_number - 1)
        if (+Number(e.total_number) > 0 && e.buy_start_time) {
          let endTime = new Date(end)
          e.buy_end_time = endTime.getFullYear() + '-' + (endTime.getMonth() + 1) + '-' + endTime.getDate() || null
        }
        this.data.splice(index, 1, e)
      }
    },
    //优惠、直减
    changeDiscount(e, index) {
      if (e.discount.value != 0) {
        e.discount.value = e.discount.value.replace(/^0+/, '')
      }
      if (e.discount.type == 1) {
        //直减计算总价
        if (e.discount.value > e.unit_price * e.buy_number) {
          e.discount.value = e.unit_price * e.buy_number
        }
        if (e.unit_price * e.buy_number - e.discount.value > 0) {
          e.signing_price = Number((e.buy_number * e.unit_price - e.discount.value).toFixed(2))
        } else {
          e.signing_price = 0
        }
      }
      if (e.discount.type == 2) {
        //折扣计算总价
        if (e.discount.value > 0 && e.discount.value < 10) {
          e.signing_price = Number((e.unit_price * e.buy_number * (e.discount.value / 10)).toFixed(2))
        } else if (e.discount.value >= 10) {
          e.discount.value = 9
          e.signing_price = Number((e.unit_price * e.buy_number * (e.discount.value / 10)).toFixed(2))
        }
      }
      this.data.splice(index, 1, e)
    },
    //定价标准切换
    changePriceType(e, index, type) {
      e.price.forEach((val) => {
        if (val.id == e.price_type) {
          e.choice_combo = val
          if (val.type == 1) {
            e.buy_start_time = null
            e.buy_end_time = null
          } else {
            e.buy_start_time = moment()
          }
          if (val.number > 1) {
            e.buy_number = val.number
            e.total_number = val.number
            e.signing_price = val.total_price
            e.unit_price = val.unit_price
            e.disable = true
            if (type !== 'add') {
              this.changeDate(e, index)
            }
          } else {
            e.buy_number = 1 //购买数量
            e.total_number = 1
            e.signing_price = val.unit_price //总价
            e.unit_price = val.unit_price
            e.disable = false
          }
          e.give_number = 0 //赠送数量
          if (type !== 'add') {
            this.changeDate(e, index)
          }
        }
      })
    },
    //购买类型
    changeCourseType(e, index) {
      this.data.splice(index, 1, e)
    },
    //删除购买项目  删完后验证 购买内容是否包含课程(没有课程允许切换校区)
    delProject(record, index) {
      this.data.splice(index, 1)
      let type = false
      this.data.forEach((val) => {
        if (val.project_type == 1) {
          type = true
        }
      })
      this.status = type
    },

    //支付
    handerPayWay(item, index) {
      this.courrent = index
      this.charge_type = this.courrent + 1
    },
    changePayWay(a, b, index) {
      // b==付款方式的Type
      // a.target.checked  选中状态
      this.copytotal = this.total
      if (a.target.checked == true) {
        let num = 0
        this.btnStyle.forEach((val) => {
          num = num + Number(val.price)
        })
        console.log(num)
        let noPay = (Math.abs(this.copytotal) - num).toFixed(2)
        this.btnStyle[index].check = a.target.checked
        this.btnStyle[index].price = noPay > 0 ? noPay : 0
      } else {
        this.btnStyle[index].check = a.target.checked
        this.btnStyle[index].price = 0
      }
    },
    finishCourse() {
      let params = JSON.parse(JSON.stringify(this.form))

      // return
      if (this.orderArrModel.length == 0) {
        this.orderArr.forEach((item) => {
          if (item.out) {
            this.orderArrModel.push(item)
          }
        })
        console.log(this.orderArrModel, '进入')
      }

      if (!params.student_id) {
        this.$message.warning('请选择转课的学员!')
        return
      }
      if (!params.structures_id) {
        this.$message.warning('请选择校区')
        return
      }
      if (this.orderArr == '' || this.orderArrModel == '') {
        this.$message.warning('请选择转出课程!')
        return
      }
      if (this.data == '') {
        this.$message.warning('请选择转入课程!')
        return
      }
      this.form.refund_method = []
      if (this.total >= 0) {
        this.form.refund_method.push({
          price: this.total,
          charge_type: this.charge_type,
        })
      } else {
        let btnStyle = JSON.parse(JSON.stringify(this.btnStyle))
        btnStyle.forEach((val) => {
          if (val.check && val.price && Number(val.price) > 0) {
            this.form.refund_method.push({
              charge_type: val.type,
              price: val.price,
            })
          }
        })
      }
      this.form.purchase_at = moment(this.$refs.otherInfo.todayDate).format('YYYY-MM-DD')
      this.form.remarks = this.$refs.otherInfo.remarks
      this.form.user_id = this.$refs.otherInfo.user_id

      this.data.forEach((item) => {
        if (item.class_id) {
          item.class.forEach((val) => {
            if (item.class_id == val.id) {
              item.className = val.name
            }
          })
        }
      })
      // this.$refs.table1.refresh(true)
      console.log(this.data)
      console.log(this.orderArrModel, 'skdfjkds')

      this.transferVisible = true
      this.$forceUpdate()
    },
    transferHandleOk() {
      let params = JSON.parse(JSON.stringify(this.form))
      params.refund_method = []
      console.log(this.data)
      this.orderArr.forEach((item) => {
        if (item.out) {
          params.transfer_out.order_arr.push({
            order_content_id: item.id,
            number: item.returnBuyNumber,
            give_number: item.returnGiveNumber,
            money: item.returnMoney,
          })
        }
      })
      this.data.forEach((item) => {
        if (item.buy_start_time) {
          params.transfer_in.order_arr.push({
            project_id: item.id,
            project_type: item.project_type,
            buy_number: item.buy_number,
            discount: JSON.stringify(item.discount),
            signing_price: item.signing_price,
            course_type: item.course_type,
            class_id: item.class_id,
            buy_start_time: moment(item.buy_start_time).format('YYYY-MM-DD'),
            buy_end_time: item.buy_end_time,
            give_number: item.give_number,
            course_price_add_id: item.price_type,
          })
        } else {
          params.transfer_in.order_arr.push({
            project_id: item.id,
            project_type: item.project_type,
            buy_number: item.buy_number,
            discount: JSON.stringify(item.discount),
            signing_price: item.signing_price,
            course_type: item.course_type,
            class_id: item.class_id,
            // buy_start_time: moment(item.buy_start_time).format('YYYY-MM-DD'),
            // buy_end_time: item.buy_end_time,
            give_number: item.give_number,
            course_price_add_id: item.price_type,
          })
        }
      })
      if (this.total >= 0) {
        params.refund_method.push({
          price: this.total,
          charge_type: this.charge_type,
        })
      } else {
        let btnStyle = JSON.parse(JSON.stringify(this.btnStyle))
        btnStyle.forEach((val) => {
          if (val.check && val.price && Number(val.price) > 0) {
            params.refund_method.push({
              charge_type: val.type,
              price: val.price,
            })
          }
        })
      }
      this.transferConfirmLoading = true
      console.log(params)

      createTransferCourse(params)
        .then((res) => {
          this.transferVisible = false
          this.transferConfirmLoading = false
          this.$message.success('转课成功')
          // this.$router.go(-1)
          this.$router.push({
            name: 'receipt',
            query: {
              type: 'transfrom',
              id: res.id,
            },
          })
        })
        .catch((err) => {
          this.transferConfirmLoading = false
          this.$message.error(err.data.message || '转课失败')
        })
    },
    transferHandleCancel() {
      this.transferVisible = false
      this.transferConfirmLoading = false
    },
  },
  watch: {
    data: {
      handler(val) {
        let num = 0
        val.forEach((item) => {
          num = num + Number(item.signing_price)
        })
        if (num > 0) {
          this.transferInMoney = num.toFixed(2)
        } else {
          this.transferInMoney = null
        }
      },
      deep: true,
    },
    returnSumMoney: {
      handler(val) {
        this.total = val - this.transferInMoney
      },
      deep: true,
    },
    transferInMoney: {
      handler(newval) {
        this.total = this.returnSumMoney - newval
      },
      deep: true,
    },
    btnStyle: {
      handler(val) {
        let num = 0
        val.forEach((item) => {
          if (item.check == true) {
            num = num + Number(item.price)
          }
        })
        this.copytotal = num.toFixed(2)
      },
      deep: true,
    },
  },
}
</script>

<style lang="less" scoped>
.receivable {
  text-align: right;
  padding-bottom: 8px;
  .receivable_num {
    font-size: 18px;
    color: #ff8534;
  }
}
.sum-money {
  line-height: 1;
  margin-left: 5px;
  font-size: 18px;
  color: #ff8534;
}
.title {
  font-size: 16px;
  color: #333;
  font-weight: 700;
}
.mr8 {
  margin-right: 8px;
}
.mt16 {
  margin-top: 16px;
  text-align: center;
}
.mt8 {
  margin-top: 8px;
}
.mb10 {
  margin-bottom: 10px;
}
.pt8 {
  padding-top: 8px;
  border-top: 1px solid #e8e8e8;
}
.headertitle {
  font-size: 16px;
  color: #333;
  line-height: 48px;
  font-weight: 500;
  border-bottom: 1px solid #e8e8e8;
}
.pay-way {
  .title {
    color: #333;
    margin-top: 13px;
    font-weight: 500;
    font-size: 14px;
    line-height: 20px;
    margin-bottom: 10px;
  }
  .refund-list {
    .active {
      border-color: rgb(255, 133, 52) !important;
    }
    .refund-item {
      cursor: pointer;
      display: inline-block;
      height: 40px;
      line-height: 40px;
      border-radius: 4px;
      border: 1px solid #d4d4d4;
      padding: 0 20px;
      color: #373737;
      margin-right: 10px;
      margin-top: 16px;
    }
  }
}
.mytitle {
  margin-top: 13px;
  color: #333;
  font-weight: 500;
  font-size: 14px;
  line-height: 20px;
  margin-bottom: 10px;
}
.payWays {
  display: flex;
  flex-wrap: wrap;
  .payWayBtn {
    display: flex;
    align-items: center;
    width: 270px;

    height: 40px;
    padding: 0 13px;
    border: 1px solid #e8e8e8;
    margin: 0 10px 10px 0;
    border-radius: 4px;
    align-items: center;
  }
}
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px 80px 10px 50px;
  margin: 0;
  box-shadow: 0 0 8px 0 #ccc;
  text-align: right;
  background: #fff;
  z-index: 16;
}
.ant-modal-body {
  max-height: 70vh;
  overflow-y: auto;
  padding: 24px;
}
.check-header {
  border-bottom: 1px solid #e8e8e8;
  padding-bottom: 12px;
  margin-bottom: 16px;
}
</style>